{
	name:"PathFocus",
	importCommand:[{
		key:"BaseEditMX",
		path:"./paint_tool/base-edit.mx"
	}],
	onFocusIn(){
		this.ghostCtx.pathMode = false
	},
	onFocusOut(){
		this.ghostCtx.pathMode = false
		this.target = null
	},
	onInit(){
		this.mixin([BaseEditMX])
		this.init()
		this.$version.on(EN.remove,(ids)=>{
			if(!this.active)return 
			this.target=null
		})
	},
	onMouseup(pos){
		this.clearRect()
		if(!this.target)return
		
		if(this.cvsMode){
			this.onCvsUp(pos)
			this.cvsMode = false
		}else{
			if(!this.cacheRes)return
			if(this.cacheRes.r.isEmpty())return
			this.onPathDragEnd(pos)
			this.cacheRes = null
		}

		this.target = null
		this.ghostCtx.pathMode = false
	},
	onMousemove(pos){
		if(!this.target)return
		this.updateFlag(1)
		this.clearRect()
		if(this.cvsMode)
			this.onCvsDraging(pos)
		else
			this.onPathDraging(pos)
	},
	onMousedown(pos){
		this.clearRect()
		//以防鼠标移动到外围 up事件没有触发
		if(this.target)this.onMouseup(pos)
		this.updateFlag(0)
		this.ghostCtx.pathMode = true
		this.cvsMode = this.$version.queryInPath(pos).isEmpty()
		if(this.cvsMode)
			this.onCvsDragStart(pos)
		else
			this.onPathDragStart(pos)
	},
	onCvsUp(pos){
		this.ghostCvs.style.cursor="default"
		this.$event.emit(EN.action,{action:"onCvsDragEnd",data:this.getDRect(pos)})
	},
	onCvsDraging(pos){
		this.ghostCvs.style.cursor="grabbing"
		this.$event.emit(EN.action,{action:"onCvsDraging",data:this.getDRect(pos)})
	},
	onCvsDragStart(pos){
		this.ghostCvs.style.cursor = "grab"
		this.target = pos
	},
	onPathDragStart(pos){
		this.cacheRes = this.$version.queryInPathPoint(pos)
		let {r,l,idx,rts} = this.cacheRes
		if(r.isEmpty()) return
		this.target = pos

		r.forEach((s)=>{
			this.hpath(s)
		})
		for(let k in rts){
			rts[k].forEach(rt=>{
				this.hpath(rt)
			})
		}
		this.$event.emit(EN.action,{action:"onPathDragStart",data:l})
	},
	onPathDraging(pos){
		this.onUpdateVData(pos,false)
	},
	onPathDragEnd(pos){
		this.onUpdateVData(pos,true)
	},
	onUpdateVData(pos,done){
		let {x,y,tx,ty} = this.target
		let dp = {
			dx:pos.x-x,
			dy:pos.y-y
		}
		let {r,l,idx} = this.cacheRes
		r.forEach((stepData,i)=>{
			let tool = this.loadMngByAction(stepData.action)
			let sd=tool.updatePath(stepData.assign(),dp,idx[i])
			if(done)
				stepData.step = sd.step
			else 
				tool.pathFocus(sd)
		});
		if(done)
			this.$version.create({r,l})
	},
	getDRect(pos){
		let step = this.target
		let {x,y} = pos
		let dx = x - step.x
		let dy = y - step.y
		return {dx,dy}
	}
}